#ifndef __USER_CONFIG_H__
#define __USER_CONFIG_H__

#define USE_OPTIMIZE_PRINTF
/*
 *
 * 引脚定义
 */
#define WIFI_STATE_PIN_NUM         GPIO_ID_PIN(12)
#define WIFI_STATE_PIN_FUNC        FUNC_GPIO12
#define WIFI_STATE_PIN_MUX         PERIPHS_IO_MUX_MTDI_U

#define WIFI_STATE_PIN_RD_INIT()   GPIO_DIS_OUTPUT(WIFI_STATE_PIN_NUM)
#define WIFI_STATE_PIN_WR_INIT()   PIN_FUNC_SELECT( WIFI_STATE_PIN_MUX, WIFI_STATE_PIN_FUNC)
#define WIFI_STATE_PIN_SET_HIGH()  GPIO_OUTPUT_SET(WIFI_STATE_PIN_NUM,1)
#define WIFI_STATE_PIN_SET_LOW()   GPIO_OUTPUT_SET(WIFI_STATE_PIN_NUM,0)
#define WIFI_STATE_PIN_STATUS      ( GPIO_INPUT_GET(WIFI_STATE_PIN_NUM) != 0 )

#define SWITCH_Pin_NUM         GPIO_ID_PIN(4)
#define SWITCH_Pin_FUNC        FUNC_GPIO4
#define SWITCH_Pin_MUX         PERIPHS_IO_MUX_GPIO4_U

#define SWITCH_Pin_Rd_Init()   GPIO_DIS_OUTPUT(SWITCH_Pin_NUM)
#define SWITCH_Pin_Wr_Init()   PIN_FUNC_SELECT(SWITCH_Pin_MUX,SWITCH_Pin_FUNC)
#define SWITCH_Pin_Set_High()  GPIO_OUTPUT_SET(SWITCH_Pin_NUM,1)
#define SWITCH_Pin_Set_Low()   GPIO_OUTPUT_SET(SWITCH_Pin_NUM,0)
#define SWITCH_Pin_State       ( GPIO_INPUT_GET(SWITCH_Pin_NUM) != 0 )
#define SWITCH_Pin_Pullup()      PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO4_U);

/**
 *tcpserver  端口号
 */
#define    SERVER_LOCAL_PORT      1112
/*
 *
 *厂家topic选择
 */
#define _FENGWEN_TOPIC
//#define _HEISENLIN_TOPIC
//#define _OLFINITY_TOPIC
//#define _BBAIR_TOPIC
//#define _QLJ_TOPIC
//#define _JINGGE_TOPIC
//#define _MOFENG_TOPIC
/*
 *
 *mqtt 服务器配置参数
 */
#if defined(_BBAIR_TOPIC)
	#define    MQTT_SERVER    "mqtt.bbair.iotplc.cn"
	#define    MQTT_PORT      1883
	#define    MQTT_ACCOUNT   ""
	#define    MQTT_PWD       ""
	#define    MQTT_QOS       1
#elif defined(_QLJ_TOPIC)
	#define    MQTT_SERVER    "mqtt.qinglangjia.iotplc.cn"
	#define    MQTT_PORT      1883
	#define    MQTT_ACCOUNT   ""
	#define    MQTT_PWD       ""
	#define    MQTT_QOS       1
#elif defined(_FENGWEN_TOPIC)
	#define    MQTT_SERVER    "mqtt.iotplc.cn"
	#define    MQTT_PORT      1883
	#define    MQTT_ACCOUNT   ""
	#define    MQTT_PWD       ""
	#define    MQTT_QOS       1
#elif defined(_JINGGE_TOPIC)
	#define    MQTT_SERVER    "mqtt.jingge.iotplc.cn"
	#define    MQTT_PORT      1883
	#define    MQTT_ACCOUNT   ""
	#define    MQTT_PWD       ""
	#define    MQTT_QOS       1
#elif defined(_MOFENG_TOPIC)
	#define    MQTT_SERVER    "mqtt.mofeng.iotplc.cn"
	#define    MQTT_PORT      1883
	#define    MQTT_ACCOUNT   ""
	#define    MQTT_PWD       ""
	#define    MQTT_QOS       1
#else
	#define    MQTT_SERVER    "mqtt.iotplc.cn"
	#define    MQTT_PORT      1883
	#define    MQTT_ACCOUNT   ""
	#define    MQTT_PWD       ""
	#define    MQTT_QOS       1
#endif

/*
 *
 * 厂家微信ID选择
 */
#define ID_WX
//#define ID_BBAIR
//#define ID_QLJ
//#define ID_JINGGE
//#define ID_MOFENG
/*
 *协议类型选择
 */
#define _DT_PROTOCOL  //aa开头
//#define _FW_PROTOCOL   //aa 55 aa 55
//#define _ALI_PROTOCOL
//#define _OLFINITY_PROTOCOL
/**
 * 通讯方式选择
 */
#define _COMM_PRO_SEL_MQTT  //通讯方式选择
//#define _COMM_PRO_SEL_HTTP

//是否选择串口0切换+串口1打印，如果不选择默认为串口0
//#define _SERIAL_SEL

//是否需要硬件控制进入网络配置状态和硬件指示状态
#define _HARDWARE_OP

//是否打开设备发现功能
//#define _DEVICE_FIND

//是否开启调试功能
//#define _DEBUG_USER


extern  char mqtt_mac[12];
extern  uint8_t sta_mac[6];
extern  uint8_t module_net_state;
extern char send_topic_up[];
extern char send_topic_down[];
extern char* domin_server;
extern uint16_t server_port ;

extern void mqtt_init(void);
extern void mqtt_connect_to_server(void);
extern void mqtt_disconnect_from_server(void);
extern void mqtt_publish_message(char* topic,uint8_t *msg,uint8_t msg_len);
extern void smartconfig_task(void);




extern void user_timer_heartbeat_init(void);
extern void heartbeat_send(uint8_t * mac,uint8_t net_state);
extern void user_timer_wifistate_init(void);

void drv_Switch_Init( void );

extern int cmd_recv_parse(uint8_t * data);
int str_replace_mac(char* raw_str,char* one ,char* two);
void  http_start();
void post_data_server(char * data);
void get_upgrade_ip(char *ip);
void user_devicefind_init(void);
void user_tcpserver_init(uint32 port);
void tcp_server_multi_send(char *pbuf, uint16_t len);

#endif

